package com.zm.campus.controller;


import com.zm.campus.pojo.RespBean;
import com.zm.campus.pojo.RespBeanEnum;
import com.zm.campus.query.TradeQuery;
import com.zm.campus.service.ITradeService;
import com.zm.campus.util.AssertUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zm
 */
@RestController
@RequestMapping("/trade")
public class TradeController {

    @Autowired
    private ITradeService tradeService;

    //获取当前用户正在进行中的订单
    @PostMapping("getDealingData")
    public RespBean getDealingData(@RequestBody TradeQuery tradeQuery){
        return tradeService.getDealingData(tradeQuery);
    }

    //完成、取消订单
    @PostMapping("doDeal")
    public RespBean doSuccessDeal(String userId,String tradeNo,Boolean doDeal) throws IOException {//操作人的学号，订单id、完成还是取消
        AssertUtil.isTrue(StringUtils.isBlank(userId)||StringUtils.isBlank(tradeNo)||doDeal==null,RespBeanEnum.DoDealParamsNull);
        return tradeService.doDeal(userId,tradeNo,doDeal);
    }

    //重新代劳
    @PostMapping("reDeal")
    public RespBean reDeal(String rdId,boolean isDeal){
        return tradeService.reDeal(rdId,isDeal);
    }


}
